<?php
class Cprofil extends CI_Controller{
	
	function index(){
		if($this->session->userdata('tipe_user') != 2){
		$this->load->model('mprofil');
		$data['hasil'] = $this->mprofil->liat();
		$this->load->view('vprofil', $data);
		}else{
			$id_user = $this->session->userdata('id_pemandu');
			redirect('cprofil/gantiorang/'.$id_user);
		}
	}

	function nambahorang(){
		if($this->input->post('submit')) {
			$this->load->model('mprofil');
			$this->mprofil->tambah();
			redirect('cprofil/index');
		}
		$data['title'] = 'Menambah Data Profil';
		$data['judul'] = 'Tambah Pemandu';
		$data['button'] = 'Tambah';
		$data['form'] = 'cprofil/nambahorang';
		$data['input1'] = NULL;
		$data['input2'] = NULL;
		$data['input3'] = NULL;
		$this->load->view('tambahan', $data);
	}
	
	function gantiorang($id){
		if($_POST==NULL){
			$this->load->model('mprofil');
			$hasil = $this->mprofil->lihat($id);
			if ($this->session->userdata('id_pemandu') == 2) {
				$data['title'] = 'Data Pemandu';
				$data['judul'] = 'Data Anda';
			}else{
				$data['title'] = 'Mengubah Data Profil';
				$data['judul'] = 'Ubah Pemandu';
			}
			$data['form'] = 'cprofil/gantiorang/'.$hasil->id_pemandu;
			$data['button'] = 'Simpan Perubahan';
			$data['input1'] = $hasil->nama;
			$data['input2'] = $hasil->fakultas;
			$data['input3'] = $hasil->jurusan;
			$this->load->view('tambahan', $data);
		}else{
			$this->load->model('mprofil');
			$this->mprofil->update($id);
			redirect('cprofil/index');
		}
	}
	
	function buangorang($id){
		$this->load->model('mprofil');
		$this->mprofil->hapus($id);
		redirect('cprofil/index');
	}
	
	function setujuiorang($id){
		$this->load-> model('mprofil');
		$this->mprofil->oke($id);
		redirect('cprofil/index');
	}
}
?>
